#include <stdio.h>
#include <malloc.h>

typedef int Elemtype;
typedef struct Node {
    Elemtype data;
    Node *next;
} Node;
typedef struct LinkList {
    Node *first;
    Node *last;
    Node *current;
} List;

int InitLinkList(LinkList *s) {
    s->first = NULL;
    s->last = NULL;
    s->current = NULL;
    return 0;
}

int AppendLinkList(LinkList *s, Elemtype e) {
    Node *pNode;
    pNode = (Node *) malloc(sizeof(Node));
    pNode->data = e;
    pNode->next = NULL;

    if (s->first == NULL) {
        s->first = pNode;
        s->last = pNode;
        s->current = pNode;
    } else {
        s->last->next = pNode;
        s->last = pNode;
    }
    return 0;
}

int GetData(LinkList *s, int pos, Elemtype *e) {
    int i;
    Node *pNode;
    pNode = s->first;
    i = 0;
    while (pNode != NULL && i < pos) {
        pNode = pNode->next;
        i++;
    }

    if (pNode == NULL)
        return -1;
    else {
        *e = pNode->data;
        s->current = pNode;
        return 0;
    }
}

int GetNext(LinkList *s, Elemtype *e) {
    if (s->current->next != NULL) {
        s->current = s->current->next;
        *e = s->current->data;
        return 0;
    } else
        return -1;
}

int main() {
    int x, x1, x2, r1, r2;
    List s1, s2, s3;
    InitLinkList(&s1);
    InitLinkList(&s2);
    InitLinkList(&s3);
    while (true) {
        scanf("%d", &x);
        if (x != -1)
            AppendLinkList(&s1, x);
        else break;
    }
    while (true) {
        scanf("%d", &x);
        if (x != -1)
            AppendLinkList(&s2, x);
        else
            break;
    }
    r1 = GetData(&s1, 0, &x1);
    r2 = GetData(&s2, 0, &x2);
    while (r1 != -1 && r2 != -1) {
        if (x1 < x2)
            r1 = GetNext(&s1, &x1);
        else if (x1 > x2)
            r2 = GetNext(&s2, &x2);
        else {
            AppendLinkList(&s3, x1);
            r1 = GetNext(&s1, &x1);
            r2 = GetNext(&s2, &x2);
        }
    }
    r1 = GetData(&s3, 0, &x);
    if (r1 != -1)
        while (r1 != -1) {
            printf("%3d", x);
            r1 = GetNext(&s3, &x);
        }
    return 0;
}

